/**
 * 
 * 移动零
 * https://leetcode-cn.com/problems/move-zeroes/
 * @param {number[]} nums
 * @return {void} Do not return anything, modify nums in-place instead.
 */
var moveZeroes = function (nums) {

    let i
    let len = nums.length
    let notZeroIndex = 0

    for (i = 0; i < len; i++) {
        if (nums[i] !== 0) {
            nums[notZeroIndex++] = nums[i]
        }
    }
    while (notZeroIndex < len) {
        nums[notZeroIndex++] = 0
    }

};

let inputArr = [0, 1, 0, 3, 12]
moveZeroes(inputArr)
console.log(inputArr)

//================v2 要点总结===============
/**
 * 1. 这一版是参考题解，针对前一版的优化
 * 2. 采用快慢指针的思想，先将所有非零的数提到前面，然后将剩余位置赋值为0
 */